package com.ljh.cloudmusic.configuration;

import com.ljh.cloudmusic.utils.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: Themberfue
 * @date: 2025/3/8 11:42
 * @description:
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Bean // ? 将 BCryptPasswordEncoder 类交给 Spring 管理
    public BCryptPasswordEncoder getBCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**") // ? 拦截所有请求
                .excludePathPatterns("/user/login", "/user/register",
                        "/user/registerByEmailCode", "/user/loginByEmailCode",
                        "/user/getEmailByUsername", "/user/updateNewPassword",
                        "/music/getMusic", "/music/getCover",
                        "/user/getAvatar",
                        "/user/sendCode"); // ! 不需要拦截的接口
    }
}
